package QuanLyThuoc;

import KetNoiSQL.KetNoiSQL;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class Thuoc {

    private int maThuoc;
    private String tenThuoc;
    private String tenLoaiThuoc;
    private int maLoaiThuoc;
    private String tenNhaCungCap;
    private int maNhaCungCap;
    private String tenDonViTinh;
    private String maDonViTinh;
    private float gia;
    private int soLuong;
    private String nguonGoc;
    private String congDung;
    private String hanDung;
    private String huongDanDung;

    public String getHuongDanDung() {
        return huongDanDung;
    }

    public void setHuongDanDung(String huongDanDung) {
        this.huongDanDung = huongDanDung;
    }

    public int getMaLoaiThuoc() {
        return maLoaiThuoc;
    }

    public void setMaLoaiThuoc(int maLoaiThuoc) {
        this.maLoaiThuoc = maLoaiThuoc;
    }

    public int getMaNhaCungCap() {
        return maNhaCungCap;
    }

    public void setMaNhaCungCap(int maNhaCungCap) {
        this.maNhaCungCap = maNhaCungCap;
    }

    public String getMaDonViTinh() {
        return maDonViTinh;
    }

    public void setMaDonViTinh(String maDonViTinh) {
        this.maDonViTinh = maDonViTinh;
    }

    public Thuoc() {
    }

    public int getMaThuoc() {
        return maThuoc;
    }

    public void setMaThuoc(int maThuoc) {
        this.maThuoc = maThuoc;
    }

    public String getTenThuoc() {
        return tenThuoc;
    }

    public void setTenThuoc(String tenThuoc) {
        this.tenThuoc = tenThuoc;
    }

    public String getTenLoaiThuoc() {
        return tenLoaiThuoc;
    }

    public void setTenLoaiThuoc(String tenLoaiThuoc) {
        this.tenLoaiThuoc = tenLoaiThuoc;
    }

    public String getTenNhaCungCap() {
        return tenNhaCungCap;
    }

    public void setTenNhaCungCap(String tenNhaCungCap) {
        this.tenNhaCungCap = tenNhaCungCap;
    }

    public String getTenDonViTinh() {
        return tenDonViTinh;
    }

    public void setTenDonViTinh(String tenDonViTinh) {
        this.tenDonViTinh = tenDonViTinh;
    }

    public float getGia() {
        return gia;
    }

    public void setGia(float gia) {
        this.gia = gia;
    }

    public int getSoLuong() {
        return soLuong;
    }

    public void setSoLuong(int soLuong) {
        this.soLuong = soLuong;
    }

    public String getNguonGoc() {
        return nguonGoc;
    }

    public void setNguonGoc(String nguonGoc) {
        this.nguonGoc = nguonGoc;
    }

    public String getCongDung() {
        return congDung;
    }

    public void setCongDung(String congDung) {
        this.congDung = congDung;
    }

    public String getHanDung() {
        return hanDung;
    }

    public void setHanDung(String hanDung) {
        this.hanDung = hanDung;
    }

    //Xem danh sách thuốc
    public static Vector xemDanhSachThuoc() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spTaiLenBang");
            while (rs.next()) {
                Thuoc t = new Thuoc();

                t.maThuoc = rs.getInt(1);
                t.tenThuoc = rs.getString(2);
                t.tenLoaiThuoc = rs.getString(3);
                t.tenNhaCungCap = rs.getString(4);
                t.tenDonViTinh = rs.getString(5);
                t.gia = rs.getFloat(6);
                t.hanDung = rs.getString(7);
                t.congDung = rs.getString(8);

                v.add(t);
            }
        } catch (SQLException ex) {
        }
        return v;
    }
    //Xem thuốc

    public static Vector xemThuoc() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemThuoc");
            while (rs.next()) {
                Thuoc t = new Thuoc();
                t.maThuoc = rs.getInt(1);
                t.tenThuoc = rs.getString(2);
                t.maLoaiThuoc = rs.getInt(3);
                t.maNhaCungCap = rs.getInt(4);

                v.add(t);
            }
        } catch (SQLException ex) {
        }
        return v;
    }

    // Xem chi tiết thuốc,để khởi tạo giá trị ban đầu cho lớp cập nhật
    public static Vector xemChiTietThuoc() throws SQLException {
        Vector v = new Vector();
        ResultSet rs = KetNoiSQL.thucHienTruVan("spXemCTThuoc");
        while (rs.next()) {
            Thuoc t = new Thuoc();
            t.maThuoc = rs.getInt(1);
            t.maDonViTinh = rs.getString(2);
            t.gia = rs.getInt(3);
            t.soLuong = rs.getInt(4);
            t.nguonGoc = rs.getString(5);
            t.congDung = rs.getString(6);
            t.hanDung = rs.getString(7);
            t.huongDanDung = rs.getString(8);

            v.add(t);
        }
        return v;
    }

    //Thêm vào bảng thuốc
    public static int themThuoc(Thuoc t) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(t.tenThuoc);
            dsThamSo.add(t.maLoaiThuoc);
            dsThamSo.add(t.maNhaCungCap);

            i = KetNoiSQL.thucHienCapNhat("spThemThuoc", dsThamSo);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return i;
    }
    //Thêm bảng chi tiết thuốc

    public static int themChiTietThuoc(Thuoc t) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(t.maThuoc);
            dsThamSo.add(t.maDonViTinh);
            dsThamSo.add(t.gia);
            dsThamSo.add(t.soLuong);
            dsThamSo.add(t.nguonGoc);
            dsThamSo.add(t.congDung);
            dsThamSo.add(t.hanDung);
            dsThamSo.add(t.huongDanDung);
            i = KetNoiSQL.thucHienCapNhat("spThemCTThuoc", dsThamSo);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return i;
    }
    //Cập nhật bảng thuốc

    public static int capNhatThuoc(Thuoc t) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(t.maThuoc);
            dsThamSo.add(t.tenThuoc);
            dsThamSo.add(t.maLoaiThuoc);
            dsThamSo.add(t.maNhaCungCap);

            i = KetNoiSQL.thucHienCapNhat("spCNThuoc", dsThamSo);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return i;
    }

    //Cập nhật chi tiết thuốc
    public static int capNhatChiTietThuoc(Thuoc t) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(t.maThuoc);
            dsThamSo.add(t.maDonViTinh);
            dsThamSo.add(t.gia);
            dsThamSo.add(t.soLuong);
            dsThamSo.add(t.nguonGoc);
            dsThamSo.add(t.congDung);
            dsThamSo.add(t.hanDung);
            dsThamSo.add(t.huongDanDung);
            i = KetNoiSQL.thucHienCapNhat("spCNCTThuoc", dsThamSo);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return i;
    }

    //Xóa thuốc
    public static int xoaThuoc(int maThuoc) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(maThuoc);
            i = KetNoiSQL.thucHienCapNhat("spXoaThuoc", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }

    //Tìm kiếm thuốc
    public static Vector timKiem(String tenSP, Vector tkThuoc) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan(tenSP, tkThuoc);
            while (rs.next()) {
                Thuoc thuoc = new Thuoc();
                thuoc.maThuoc = rs.getInt(1);
                thuoc.tenThuoc = rs.getString(2);
                thuoc.tenLoaiThuoc = rs.getString(3);
                thuoc.tenNhaCungCap = rs.getString(4);
                thuoc.tenDonViTinh = rs.getString(5);
                thuoc.gia = rs.getFloat(6);
                thuoc.hanDung = rs.getString(7);
                thuoc.congDung = rs.getString(8);
                v.add(thuoc);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
}
